package com.bytedance.common.plugin.mop;

import android.util.Log;

import com.bytedance.common.plugin.framework.util.PluginUtil;

import java.util.List;

public class MopAdapter {

    public void mopAction(Class[] parameterTypes, Object[] args) {
        try {
            StackTraceElement stackTraceElement = PluginUtil.getCallerStackTraceElement();
            if (stackTraceElement != null) {
                MopImplCaller mopImplCaller = new MopImplCaller(stackTraceElement, parameterTypes, args);
                mopImplCaller.execAction();
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    public List mopFunc(Class[] arg3, Object[] arg4) {
        try {
            StackTraceElement stackTraceElement = PluginUtil.getCallerStackTraceElement();
            if (stackTraceElement == null) {
                return null;
            }
            MopImplCaller mopImplCaller = new MopImplCaller(stackTraceElement, arg3, arg4);
            List result = mopImplCaller.execFunc();
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        return null;
    }

    public Object mopFuncSingle(Class[] parameterTypes, Object[] args) {
        try {
            StackTraceElement stackTraceElement = PluginUtil.getCallerStackTraceElement();
            if (stackTraceElement == null) {
                return null;
            }
            MopImplCaller mopImplCaller = new MopImplCaller(stackTraceElement, parameterTypes, args);
            Object result = mopImplCaller.execFuncSingle();
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }
}

